﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectSem3
{
    public partial class WebForm16 : System.Web.UI.Page
    {
         private DataClassesHealthDataContext dc = new DataClassesHealthDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                EmpRegister Semp = (EmpRegister)Session["member"];
                if (Semp == null)
                {
                    Response.Redirect("member.aspx");
                }
                else
                {
                    gandulieu();
                }
            }
        }

        protected void ButtonUpdate_Click(object sender, EventArgs e)
        {
            string firstname = this.TextBoxFirstname.Text;
            string lastname = this.TextBoxLastname.Text;
            string salary = this.TextBoxSalary.Text;
            string address = this.TextBoxAddress.Text;
            string contactinfo = this.TextBoxContact.Text;
            string country = this.TextBoxCountry.Text;
            string city = this.TextBoxCity.Text;
            update(firstname, lastname, salary, address, contactinfo, country, city);
            gandulieu();
        }
        public void update(string firstname, string lastname, string salary, string address, string contactinfo, string country, string city)
        {
            EmpRegister Semp = (EmpRegister)Session["member"];

            EmpRegister emp = this.dc.EmpRegisters.Single(e=>e.empno==Semp.empno);
            emp.firstname = firstname;
            emp.lastname = lastname;
            emp.salary = Convert.ToDecimal(salary);
            emp.address = address;
            emp.contactinfo = contactinfo;
            emp.country = country;
            emp.city = city;
            dc.SubmitChanges();

        }
        public void gandulieu()
        {
            EmpRegister Semp = (EmpRegister)Session["member"];
            EmpRegister emp = new EmpRegister();
            emp = this.dc.EmpRegisters.Single(h => h.username.Equals(Semp.username));
            this.Label1Username.Text = emp.username;
            this.TextBoxFirstname.Text = emp.firstname;
            this.TextBoxLastname.Text = emp.lastname;
            this.LabelJoindate.Text = string.Format("{0:dd/MM/yyyy}", emp.joindate);
            this.TextBoxSalary.Text = String.Format("{0:0.##}", emp.salary);
            this.TextBoxAddress.Text = emp.address;
            this.TextBoxContact.Text = emp.contactinfo;
            this.TextBoxCountry.Text = emp.country;
            this.TextBoxCity.Text = emp.city;
        }
    }
}
    